package leetcode.twopoint;

import leetcode.linkedlist.common.LinkedListUtils;
import leetcode.linkedlist.common.ListNode;
import leetcode.twopoint.common.TwoPointUtils;

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution19 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        return TwoPointUtils.removeNthFromEnd(head, n);
    }
}

public class leetcode19 {
    public static void main(String[] args) {
        Solution19 solution19 = new Solution19();
        int[] nums = {1,2,3,4,5,6};
        deleteNthNodeFromEnd(solution19, nums, 1);
        deleteNthNodeFromEnd(solution19, nums, 6);
        deleteNthNodeFromEnd(solution19, nums, 3);
        deleteNthNodeFromEnd(solution19, nums, 2);
    }

    private static void deleteNthNodeFromEnd(Solution19 solution19, int[] nums, int n) {
        // 每次都会根据 nums 生成一个新的链表
        ListNode head = LinkedListUtils.generateLinkedListByArray(nums);
//        System.out.println(LinkedListUtils.getLinkedListVals(head));
        ListNode removeNthFromEnd = solution19.removeNthFromEnd(head, n);
        System.out.println(LinkedListUtils.getLinkedListVals(removeNthFromEnd));
    }
}
